//
//  XMFactoryModel.m
//  XMKit
//
//  Created by chenming on 2017/12/23.
//  Copyright © 2017年 ChenXiaoMing. All rights reserved.
//

#import "XMFactoryModel.h"

@implementation XMFactoryModel

- (void)setKind:(NSString *)kind {
    if ([kind isEqualToString:@"1"]) {
        // 显示图片
        _state = XMFactoryModelStyleFirst;
        CGFloat height = [self sizeWithText:self.name maxSize:CGSizeMake(kSCREEN_WIDTH - 110, MAXFLOAT) fontSize:14].height;
        if (height > 100) {
            _cellHeight = height;
        } else {
            _cellHeight = 100;
        }
    } else {
        // 不显示图片
        _state = XMFactoryModelStyleSecond;
        CGFloat height = [self sizeWithText:self.name maxSize:CGSizeMake(kSCREEN_WIDTH, MAXFLOAT) fontSize:14].height;
        _cellHeight = height;
    }
}

- (CGSize)sizeWithText:(NSString *)text maxSize:(CGSize)maxSize fontSize:(CGFloat)fontSize {
    //计算文本的大小
    CGSize nameSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    return nameSize;
}

@end
